package top.jnaw.jee.utils.baidu;

import com.jfinal.kit.PropKit;
import java.net.URLEncoder;
import top.jnaw.jee.utils.Log;

/**
 * 营业执照识别
 */
public class BusinessLicense {

  public static String getLicense(String filePath) {
    // 识别营业执照url
    String licenseIdentificate = PropKit.get("baidu_license_url");
    // 本地图片路径
//    String filePath = "D:/images/license.jpg";
    String result = "";
    try {
      byte[] imgData = FileUtil.readFileByBytes(filePath);
      String imgStr = Base64Util.encode(imgData);
      String params =
          URLEncoder.encode("image", "UTF-8") + "="
              + URLEncoder.encode(imgStr, "UTF-8");

      String accessToken = AuthService.getAuth();
      result = HttpUtil.post(licenseIdentificate, accessToken, params);
    } catch (Exception e) {
      Log.w("识别营业执照失败");
      e.printStackTrace();
    }
    return result;
  }


}
